package com.mall.b2c.bean;

import java.math.BigDecimal;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import com.mall.b2c.domain.goods.GoodsCategoryDomain;
import com.mall.b2c.domain.goods.GoodsDomain;
import com.mall.b2c.domain.goods.GoodsIntroductionDomain;
import com.mall.b2c.domain.member.MemberDomain;
import com.mall.b2c.enums.PrescribeType;
import com.mall.b2c.util.DictionaryUtils;
import com.mall.common.util.BeanUtils;
import com.mall.common.util.UploadUtil;

public class GoodsBean {

	private Long id; //商品id
	private String code;// 商品编号
	private String name;// 中文名
	private String highlighter; //商品名称lucene搜索高亮显示，仅搜索使用
	private String enName;// 英文名
	private String pyName;// 中文拼音
	private String byName;// 别名
	private String tip;//提示
	private String barcode;// 条形码
	private String spec;// 规格收藏
	private String productionArea;// 产地
	private String manufacturer;// 生产厂商

	private String prescribeType;// 处方类型,字典表关联
	private String packingUnit;// 包装单位
	private BigDecimal weight;//重量
	private BigDecimal marketPrice;// 建议零售价
	private BigDecimal price;//销售价
	private String medicalInsuranceType;//医保类型
	private String medicalInsuranceCode;// 医保编号

	private String authorizeNumber;// 批准文号
	private String businessScope;// 经营范围
	private Integer stock;// 库存
	private String goodsType;// 商品类别,字典表关联
	private String instrumentLicence;// 医疗器械许可证号

	private String keyword;// 搜索关键字
	private Boolean isMarketable;// 是否上架
	private Integer sales;// 购买数量
	private Integer cmts;//评论数
	private JSONObject cmtsJson;
	private Integer views;// 商品浏览次数
	private Boolean hadEphedrine;// 是否含麻黄碱
	private Boolean isRefrigerate;// 是否冷藏

	private String drugForm;// 剂型
	private String message;// 商品信息
	
	private BrandBean  brand;// 品牌
	private Long goodsCategoryId;// 商品分类
	private String goodsCategoryCode; //商品分类code
	private JSONArray cateTreePath; //商品分类树路径
	private Introduction introduction;// 药品说明书

	private String image_default; // 商品图片路径存储
	private String[] image_files; //商品图片
	private Boolean hasCollected;//是否收藏

	private Double integralRate; //积分兑换比率

	public GoodsBean(GoodsDomain goods) {
		this(goods, null);
	}
	
	public GoodsBean(GoodsDomain goods, MemberDomain member) {
		super();
		BeanUtils.copyProperties(goods, this, new String[] {"cmtsJson", "brand"});
		/**商品评论*/
		if(StringUtils.isNotBlank(goods.getCmtsJson())) {
			cmtsJson = JSONObject.fromObject(goods.getCmtsJson());
		}
		/**是否收藏*/
		hasCollected = goods.hasCollected(member);
		/**处方类型*/
//		PrescribeType prescribeType = goods.getPrescribeType();
		if(prescribeType != null) {
			setPrescribeType(DictionaryUtils.getEnumName(prescribeType));
		}
		/**品牌*/
		if(goods.getBrand() != null) {
			brand = new BrandBean(goods.getBrand());
		}
		
		String unitcode = goods.getPackingUnit();
		if(StringUtils.isNotBlank(unitcode)){
			setPackingUnit(DictionaryUtils.getDictionaryValue(unitcode).getString("name"));
		}
		
		setImage_default(UploadUtil.replacePath(image_default));
		String[] imgs = goods.getImageList();
		if(!ArrayUtils.isEmpty(imgs)){
			for(int i = 0; i < imgs.length; i++){
				imgs[i] = UploadUtil.replacePath(imgs[i]);
			}
			imgs = ArrayUtils.add(imgs, 0, getImage_default());
		}else{
			imgs = new String[]{ getImage_default()};
		}
		setImage_files(imgs);
		
//		GoodsIntroductionDomain introduction = goods.getGoodsIntroduction();
//		if(introduction != null){
//			setIntroduction(new Introduction(introduction));
//		}

		GoodsCategoryDomain goodsCategory = goods.getGoodsCategory();
		if(goodsCategory != null) {
			setGoodsCategoryId( goodsCategory.getId() );
			setGoodsCategoryCode(goodsCategory.getCode());
			cateTreePath = new JSONArray();
			do {
				JSONObject obj = new JSONObject();
				obj.put("id", goodsCategory.getId());
				obj.put("name", goodsCategory.getName());
				cateTreePath.add(0, obj);
				goodsCategory = goodsCategory.getParent();
			} while (goodsCategory != null);
		}
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getHighlighter() {
		return highlighter;
	}

	public void setHighlighter(String highlighter) {
		this.highlighter = highlighter;
	}

	public String getEnName() {
		return enName;
	}

	public void setEnName(String enName) {
		this.enName = enName;
	}

	public String getPyName() {
		return pyName;
	}

	public void setPyName(String pyName) {
		this.pyName = pyName;
	}

	public String getByName() {
		return byName;
	}

	public void setByName(String byName) {
		this.byName = byName;
	}

	public String getTip() {
		return tip;
	}

	public void setTip(String tip) {
		this.tip = tip;
	}

	public String getBarcode() {
		return barcode;
	}

	public void setBarcode(String barcode) {
		this.barcode = barcode;
	}

	public String getSpec() {
		return spec;
	}

	public void setSpec(String spec) {
		this.spec = spec;
	}

	public String getProductionArea() {
		return productionArea;
	}

	public void setProductionArea(String productionArea) {
		this.productionArea = productionArea;
	}

	public String getManufacturer() {
		return manufacturer;
	}

	public void setManufacturer(String manufacturer) {
		this.manufacturer = manufacturer;
	}

	public String getPrescribeType() {
		return prescribeType;
	}

	public void setPrescribeType(String prescribeType) {
		this.prescribeType = prescribeType;
	}

	public String getPackingUnit() {
		return packingUnit;
	}

	public void setPackingUnit(String packingUnit) {
		this.packingUnit = packingUnit;
	}

	public BigDecimal getWeight() {
		return weight;
	}

	public void setWeight(BigDecimal weight) {
		this.weight = weight;
	}

	public BigDecimal getMarketPrice() {
		return marketPrice;
	}

	public void setMarketPrice(BigDecimal marketPrice) {
		this.marketPrice = marketPrice;
	}

	public BigDecimal getPrice() {
		return price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}

	public String getMedicalInsuranceType() {
		return medicalInsuranceType;
	}

	public void setMedicalInsuranceType(String medicalInsuranceType) {
		this.medicalInsuranceType = medicalInsuranceType;
	}

	public String getMedicalInsuranceCode() {
		return medicalInsuranceCode;
	}

	public void setMedicalInsuranceCode(String medicalInsuranceCode) {
		this.medicalInsuranceCode = medicalInsuranceCode;
	}

	public String getAuthorizeNumber() {
		return authorizeNumber;
	}

	public void setAuthorizeNumber(String authorizeNumber) {
		this.authorizeNumber = authorizeNumber;
	}

	public String getBusinessScope() {
		return businessScope;
	}

	public void setBusinessScope(String businessScope) {
		this.businessScope = businessScope;
	}

	public Integer getStock() {
		return stock;
	}

	public void setStock(Integer stock) {
		this.stock = stock;
	}

	public String getGoodsType() {
		return goodsType;
	}

	public void setGoodsType(String goodsType) {
		this.goodsType = goodsType;
	}

	public String getInstrumentLicence() {
		return instrumentLicence;
	}

	public void setInstrumentLicence(String instrumentLicence) {
		this.instrumentLicence = instrumentLicence;
	}

	public String getKeyword() {
		return keyword;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}

	public Boolean getIsMarketable() {
		return isMarketable;
	}

	public void setIsMarketable(Boolean isMarketable) {
		this.isMarketable = isMarketable;
	}

	public Integer getSales() {
		return sales;
	}

	public void setSales(Integer sales) {
		this.sales = sales;
	}

	public Integer getCmts() {
		return cmts;
	}

	public void setCmts(Integer cmts) {
		this.cmts = cmts;
	}

	public JSONObject getCmtsJson() {
		return cmtsJson;
	}

	public void setCmtsJson(JSONObject cmtsJson) {
		this.cmtsJson = cmtsJson;
	}

	public Integer getViews() {
		return views;
	}

	public void setViews(Integer views) {
		this.views = views;
	}

	public Boolean getHadEphedrine() {
		return hadEphedrine;
	}

	public void setHadEphedrine(Boolean hadEphedrine) {
		this.hadEphedrine = hadEphedrine;
	}

	public Boolean getIsRefrigerate() {
		return isRefrigerate;
	}

	public void setIsRefrigerate(Boolean isRefrigerate) {
		this.isRefrigerate = isRefrigerate;
	}

	public String getDrugForm() {
		return drugForm;
	}

	public void setDrugForm(String drugForm) {
		this.drugForm = drugForm;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public BrandBean getBrand() {
		return brand;
	}

	public void setBrand(BrandBean brand) {
		this.brand = brand;
	}

	public Long getGoodsCategoryId() {
		return goodsCategoryId;
	}

	public void setGoodsCategoryId(Long goodsCategoryId) {
		this.goodsCategoryId = goodsCategoryId;
	}
	
	public String getGoodsCategoryCode() {
		return goodsCategoryCode;
	}

	public void setGoodsCategoryCode(String goodsCategoryCode) {
		this.goodsCategoryCode = goodsCategoryCode;
	}

	public Introduction getIntroduction() {
		return introduction;
	}

	public void setIntroduction(Introduction introduction) {
		this.introduction = introduction;
	}

	public String getImage_default() {
		return image_default;
	}

	public void setImage_default(String image_default) {
		this.image_default = image_default;
	}

	public String[] getImage_files() {
		return image_files;
	}

	public void setImage_files(String[] image_files) {
		this.image_files = image_files;
	}

	public JSONArray getCateTreePath() {
		return cateTreePath;
	}

	public void setCateTreePath(JSONArray cateTreePath) {
		this.cateTreePath = cateTreePath;
	}

	public Boolean getHasCollected() {
		return hasCollected;
	}

	public void setHasCollected(Boolean hasCollected) {
		this.hasCollected = hasCollected;
	}

	public Double getIntegralRate() {
		return integralRate;
	}

	public void setIntegralRate(Double integralRate) {
		this.integralRate = integralRate;
	}
}

